package com.zpark.cz.workfair;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.zpark.cz.util.ConnectionUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    private static final String QUEUE_NAME = "test-work_fair-queue";
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        // 获取连接
        Connection conn = ConnectionUtil.getConnection();
        // 获得通道
        Channel channel = conn.createChannel();
        // 声明队列
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        for(int i=0; i<100; i++){
            String msg = "Hello, World! " + i;
            channel.basicPublish("", QUEUE_NAME, null, msg.getBytes());
            System.out.println("生产者：发送消息 msg -> " + msg);
        }
        channel.close();
        conn.close();
    }
}
